import { createRouter, createWebHistory } from 'vue-router'
// 创建路由器实例
const router = createRouter({
  history: createWebHistory(), // 路由器工作模式为history模式
  // 路由规则
  routes: [
    // 根路由
    {
      path: '/',
      redirect: '/home',
    },
    // 微信登录路由
    {
      path: '/wxlogin',
      name: 'wxlogin',
      component: () => import('@/pages/wxlogin/index.vue'),
    },
    // 首页一级路由
    {
      name: 'home',
      path: '/home',
      component: () => import('@/pages/home/index.vue'), // 路由懒加载
      meta: {
        title: '首页',
      },
    },
    // 医院详情一级路由
    {
      name: 'hospital',
      path: '/hospital',
      component: () => import('@/pages/hospital/index.vue'),
      // 医院详情子路由
      children: [
        {
          name: 'register',
          path: 'register',
          component: () => import('@/pages/hospital/register/index.vue'),
          meta: {
            title: '预约挂号',
          },
        },
        {
          name: 'detail',
          path: 'detail',
          component: () => import('@/pages/hospital/detail/index.vue'),
          meta: {
            title: '医院详情',
          },
        },
        {
          name: 'notice',
          path: 'notice',
          component: () => import('@/pages/hospital/notice/index.vue'),
          meta: {
            title: '预约须知',
          },
        },
        {
          name: 'close',
          path: 'close',
          component: () => import('@/pages/hospital/close/index.vue'),
          meta: {
            title: '停诊信息',
          },
        },
        {
          name: 'search',
          path: 'search',
          component: () => import('@/pages/hospital/search/index.vue'),
          meta: {
            title: '查询/取消',
          },
        },
        {
          name: 'registerStepOne',
          path: 'register_step_one',
          component: () =>
            import('@/pages/hospital/register/RegisterStepOne.vue'),
          meta: {
            title: '挂号信息填写',
          },
        },
        {
          name: 'registerStepTwo',
          path: 'register_step_two',
          component: () =>
            import('@/pages/hospital/register/RegisterStepTwo.vue'),
          meta: {
            title: '挂号人信息选择',
          },
        },
      ],
    },
    // 用户信息一级路由
    {
      path: '/user',
      name: 'user',
      component: () => import('@/pages/user/index.vue'),
      // 重定向到实名认证二级路由
      redirect: '/user/identification',
      children: [
        {
          path: 'identification',
          name: 'identification',
          component: () => import('@/pages/user/identification/index.vue'),
          meta: {
            title: '实名认证',
          },
        },
        {
          path: 'order',
          name: 'order',
          component: () => import('@/pages/user/order/index.vue'),
          meta: {
            title: '挂号订单',
          },
        },
        {
          path: 'patient',
          name: 'patient',
          component: () => import('@/pages/user/patient/index.vue'),
          meta: {
            title: '就诊人管理',
          },
        },
        {
          path: 'account',
          name: 'account',
          component: () => import('@/pages/user/account/index.vue'),
          meta: {
            title: '账号信息',
          },
        },
        {
          path: 'feedback',
          name: 'feedback',
          component: () => import('@/pages/user/feedback/index.vue'),
          meta: {
            title: '意见反馈',
          },
        },
      ],
    },
    // 404路由一级路由
    {
      path: '/404',
      name: '404',
      component: () => import('@/pages/404/index.vue'),
      meta: {
        title: '404',
      },
    },
    // 任意路由
    {
      path: '/:pathMatch(.*)*',
      redirect: '/404',
    },
  ],
  // 滚动行为(当切换路由时，滚动条会回到顶部)
  scrollBehavior() {
    return {
      left: 0,
      top: 0,
    }
  },
})
// 将路由器暴露出去
export default router
